﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web.Security;
using System.Net;

namespace DevExpress.CrmDemo.Win
{
    public partial class login : Form
    {
        public login()
        {
            InitializeComponent();
        }
        public static string AppDomain = System.Configuration.ConfigurationManager.AppSettings["appDomain"];

        private void button1_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            return;
            if (this.txtUser.Text.Trim() == "")
            {
                MessageBox.Show("用户名不能为空！");
               // this.DialogResult = System.Windows.Forms.DialogResult.No;
                return;
            }
            if (this.txtPassword.Text.Trim() == "")
            {
                MessageBox.Show("密码不能为空！");
                //this.DialogResult = System.Windows.Forms.DialogResult.No;
                return;
            }
          

               WebClient wc = new WebClient();
            Byte[] pageData = wc.DownloadData(AppDomain + string.Format( "validateLoginHanlder.ashx?user={0}&password={1}"
                                                       , System.Web.HttpUtility.UrlEncode( this.txtUser.Text.Trim())
                                                       , FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtPassword.Text.Trim(), "MD5")
                                                       ));

            string sResult = Encoding.Default.GetString(pageData);
            if (sResult == "1")
            {
                DevExpress.CrmDemo.Win.Controls.BasePage.SloginUser = this.txtUser.Text.Trim();
                DevExpress.CrmDemo.Win.Controls.BasePage.SLoginPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtPassword.Text.Trim(), "MD5");
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            else
            {
                MessageBox.Show("用户名或者密码不正确！");
            }
            return;
           
          //  Application.Run(new MainForm());
           // this.txtPassword.
        }
    }
}
